<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/9/10
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>管理员管理首页</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/roleManagement.css">
    <script src="${pageContext.request.contextPath}/static/jquery/jquery-3.1.1.js"></script>
    <script src="${pageContext.request.contextPath}/static/jquery/jquery.validate.js"></script>
    <link rel="stylesheet" href="/static/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/static/frame/static/css/style.css">
    <link rel="icon" href="/static/frame/static/image/code.png">

    <style>
        .showmessages {
            position: absolute;
            width: 100%;
            height: 100%;
            margin-top: 100px;
        }
    </style>
</head>
<body>
<div id="div1">
    <div class="backphall">
        <div class="titleall">
            <div class="titleph">
                <img src="${pageContext.request.contextPath}/static/images/role.png" style="width:100%;height:100%;"/>
            </div>
            <div class="titleword">管理员管理 >>> 管理员列表</div>
        </div>
        <form action="selectAdmin" method="post" id="selectform">
            <input type="text" class="selectbox" name="admin_username" placeholder="管理员账号 / Name"/>
            <input type="submit" value="查询" class="selectbutton"/>
        </form>
        <div class="contentall"></div>
    </div>
    <div class="showmessages">
        <table class="layui-table">
            <thead>
            <tr>
                <th>管理员排序</th>
                <th>管理员账号</th>
                <th>姓名</th>
                <th>电话</th>
                <th>职能</th>
                <th>创建时间</th>
                <th>最后登录时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="clear" style="display: none">
            <script>var arr1 = []</script>
            <c:forEach items="${sessionScope.admin1}" var="o" varStatus="sta">
                <tr id="adminorder${sta.count}">
                    <td>${sta.count}</td>
                    <td style="display: none">${o.getAdmin_id()}<input type="hidden" name="admin_id"
                                                                       value="${o.getAdmin_id()}"></td>
                    <td>${o.getAdmin_username()}<input type="hidden" name="admin_username"
                                                       value="${o.getAdmin_username()}"></td>
                    <td>${o.getAdmin_name()}<input type="hidden" name="admin_name" value="${o.getAdmin_name()}"></td>
                    <td>${o.getAdmin_phone()}<input type="hidden" name="admin_phone" value="${o.getAdmin_phone()}"></td>
                    <td>${adminCharacter[sta.count-1].character_name}</td>
                    <c:if test="${o.getAdmin_createtime()!=null}">
                        <td><label class="createtime">${o.getAdmin_createtime()}</label><input type="hidden"
                                                                                               name="admin_createtime"
                                                                                               value="${o.getAdmin_createtime()}">
                        </td>
                    </c:if>
                    <c:if test="${o.getAdmin_createtime()==null}">
                        <td></td>
                    </c:if>
                    <c:if test="${o.getAdmin_lasttime()!=null}">
                        <td><label class="createtime">${o.getAdmin_lasttime()}</label></td>
                    </c:if>
                    <c:if test="${o.getAdmin_lasttime()==null}">
                        <td></td>
                    </c:if>
                    <c:if test="${o.getAdmin_status()!=0}">
                        <td>
                            <form method="post" style="float: left;">
                                <input type="button" name="buttonValue" value="修改"
                                       onclick="confirm(this,${o.getAdmin_id()})"
                                       style="margin-left:20px;cursor:pointer;width: 100px;height: 30px;background-color:rgba(20,180,20,0.6);border: 0px;color:white;border-radius:5px;font-style: italic;">
                            </form>
                            <form method="post" style="float: left;margin-left: 10px">
                                <input type="button" name="buttonValue" value="离职"
                                       onclick="fire(this,${o.getAdmin_id()})"
                                       style="margin-left:20px;cursor:pointer;width: 60px;height: 30px;background-color:rgba(255,0,0,0.6);border: 0px;color:white;border-radius:5px;font-style: italic">
                            </form>
                                <%--&nbsp;&nbsp;&nbsp;&nbsp;--%>
                                <%--<input  id="delete" type="submit" name="buttonValue" value="删除" style="float:left;text-align:center;line-height:30px;cursor:pointer;width: 60px;height: 30px;background-color: indianred;border: 0px">--%>
                        </td>
                    </c:if>
                    <c:if test="${o.getAdmin_status()==0}">
                        <td></td>
                    </c:if>
                </tr>
                <script>arr1.push($("#adminorder${sta.count}")[0])</script>
            </c:forEach>
            </tbody>
            <tbody id="biuuu_city_list"></tbody>
        </table>
        <div id="demo20"></div>
        <%--<div  style="width:200px;height: 30px;line-height: 30px;margin: 0px auto;">--%>
        <%--<div id="pageButton1" href="#" style="color:darkgray;width:60px;height:30px;float: left;text-align: center;border: solid 1px gray;">上一页</div>--%>
        <%--<div onclick="window.location.href='${pageContext.request.contextPath}/admin_index'" class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">1</div>--%>
        <%--<div onclick="window.location.href='${pageContext.request.contextPath}/admin_index2'" class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">2</div>--%>
        <%--<div onclick="window.location.href='${pageContext.request.contextPath}/admin_index3'" class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">3</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">4</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">5</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">6</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">7</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">8</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">9</div>--%>
        <%--<div class="a" style="width:30px;height:30px;float: left;text-align: center;border: solid 1px gray">10</div>--%>
        <%--<div onclick="window.location.href='${pageContext.request.contextPath}/admin_index2'" id="pageButton2" href="#" style="width:60px;height:30px;float: left;text-align: center;border: solid 1px gray">下一页</div>--%>
        <%--</div>--%>

    </div>

</div>

</body>
<script src="${pageContext.request.contextPath}/static/frame/layui/layui.js" charset="utf-8"></script>
<script>
    function nodeToString(node) {
        var tmpNode = document.createElement("div");
        tmpNode.appendChild(node.cloneNode(true));
        var str = tmpNode.innerHTML;
        tmpNode = node = null; // prevent memory leaks in IE
        return str;
    }

    function clear() {
        document.getElementById('clear').innerHTML = null;
    }

    layui.use(['carousel', 'laypage', 'laydate', 'form', 'upload', 'jquery'], function () {
        var carousel = layui.carousel
            , form = layui.form
            , $ = layui.jquery
            , upload = layui.upload
            , laypage = layui.laypage
            , laydate = layui.laydate

        //常规轮播
        carousel.render({
            elem: '#test1'
            , arrow: 'always'
        });
        var data1 = arr1;
        laypage.render({
            elem: 'demo20'
            , count: data1.length
            , jump: function (obj) {
                //模拟渲染
                document.getElementById('biuuu_city_list').innerHTML = function () {
                    var arr = []
                        , thisData = data1.concat().splice(obj.curr * obj.limit - obj.limit, obj.limit);
                    layui.each(thisData, function (index, item) {
                        var itemstr = nodeToString(item);
                        arr.push(itemstr);
                    });
                    clear();
                    return arr.join('');
                }();
            }
        });
    });

    function confirm(e, value) {
        $.ajax({
            type: 'POST',
            url: "${pageContext.request.contextPath}/deleteOrUpdateAdminController.do",
            data: {
                admin_id: value,
            },
            dataType: "json",
            success: function (data) {
                if (data == true) {
                    window.location.href = "${pageContext.request.contextPath}/toAdminUpdate";
                }
            }
        })
    }

    function fire(e, value) {
        $.ajax({
            type: 'POST',
            url: "${pageContext.request.contextPath}/deleteAdmin.do",
            data: {
                admin_id: value,
            },
            dataType: "json",
            success: function (data) {
                if(data){
                $.ajax({
                        type: 'POST',
                        url: "${pageContext.request.contextPath}/adminList.do",
                        data: {},
                        dataType: "json",
                        success: function () {
<%--alert("${admin1}")--%>
                        }
                    }
                )
                }
                <%--alert("${admin1}");--%>
                location.reload(true);
            }
        })
    }
    var i = 0;
    var w = $(window).width();
    var h = $(window).height();
    $(".pageall").innerHeight(h + "px");
    $(".pageall").innerWidth(w + "px");

    /**
     * 单击删除按钮时，确认框显示
     */
    <%--function click1(e,index) {--%>
    <%--$("#div2").css({"display":"block"});--%>
    <%--$("#confirm").click(function () {--%>
    <%--$.ajax({--%>
    <%--type:'POST',--%>
    <%--url:"${pageContext.request.contextPath}/deleteRepairController.do",--%>
    <%--data:{--%>
    <%--admin_id:$(".adminId")[index-1].value--%>
    <%--},--%>
    <%--dataType:"json",--%>
    <%--success:function (data) {--%>
    <%--if (data == true) {--%>
    <%--window.location.href="${pageContext.request.contextPath}/admin_index";--%>
    <%--}--%>
    <%--}--%>
    <%--})--%>
    <%--});--%>
    <%--}--%>

    /**
     * 点击“取消”按钮，确认框消失
     */
    function click3() {
        $("#div2").css({"display": "none"});
    }

    /**
     * 分页操作
     */
    showPage(this);

    function showPage(e) {
        var counts = "${sessionScope.counts}";//从后台获取查询到的所有管理员的个数
        $(".a").css({"display": "none"});//进入页面时，让显示页码的元素隐藏
        $("#pageButton1").css({"display": "none", "cursor": "pointer"});
        $("#pageButton2").css({"display": "none", "cursor": "pointer"});
        var num = counts / 6;//判断有几页，动态显示
        var as = $(".a");
        $.each(as, function (i, v) {  //遍历class为a的数组，根据条件判断显示几页
            if (i < num) {
                $(v).css({"display": "block", "cursor": "pointer"});
                $("#pageButton1").css("display", "block");
                $("#pageButton2").css("display", "block");
            }
            if (i == 0) {
                $(v).css("background", "green")  //设置显示页码的背景颜色
            }
        })
//通过后台传入的“1”或者“0”，在页面上显示“在职”和“离职”
        var status = $(".status");
        status.each(function () {   //用each（）遍历class为status的数组
            switch ($(this).text()) {
                case "0":
                    $(this).text("离职");
                    $(this).css("color", "red");
                    break;
                case "1":
                    $(this).text("在职");
                    $(this).css("color", "blue");
                    break;
                default:
                    $(this).text("其他");
                    $(this).css("color", "yellow");
            }
        });
        //遍历“创建时间”，调用时间格式转换函数
        var createtime = $(".createtime");
        createtime.each(function () {
            $(this).text(formatDateTime($(this).text()))
        })
    }

    /**
     *
     * 在页面上，转换时间格式
     * @param inputTime
     * @returns {string}
     */
    function formatDateTime(inputTime) {
        var date = new Date(inputTime);
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? ('0' + m) : m;
        var d = date.getDate();
        d = d < 10 ? ('0' + d) : d;
        var h = date.getHours();
        h = h < 10 ? ('0' + h) : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? ('0' + minute) : minute;
        second = second < 10 ? ('0' + second) : second;
        return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
    };

</script>

</html>
